import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * Created with IntelliJ IDEA
 * Details about unstoppable_t:
 * User: Administrator
 * Date: 2021-04-02
 * Time: 17:08
 */
public class Calculator extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request, response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //1.设置通用属性
        response.setCharacterEncoding("utf-8");
        response.setContentType("text/html");

        //2.获得前端传递的参数
        String num1 = request.getParameter("number1");
        String num2 = request.getParameter("number2");

        //3.业务逻辑处理
        int total = Integer.parseInt(num1) + Integer.parseInt(num2);

        //4.返回结果给前端
        PrintWriter writer = response.getWriter();
        writer.println(String.format("<h1 style='color:blue'>计算的结果为：%d</h1>",total));

    }
}
